{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Riskfolio-Lib Tutorial: \n",
    "<br>__[Financionerioncios](https://financioneroncios.wordpress.com)__\n",
    "<br>__[Orenji](https://www.orenj-i.net)__\n",
    "<br>__[Riskfolio-Lib](https://riskfolio-lib.readthedocs.io/en/latest/)__\n",
    "<br>__[Dany Cajas](https://www.linkedin.com/in/dany-cajas/)__\n",
    "<a href='https://ko-fi.com/B0B833SXD' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi1.png?v=2' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a> \n",
    "\n",
    "## Tutorial 37: OWA Portfolio Optimization\n",
    "\n",
    "## 1. Downloading the data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "[*********************100%%**********************]  25 of 25 completed\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import yfinance as yf\n",
    "import warnings\n",
    "\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "pd.options.display.float_format = '{:.4%}'.format\n",
    "\n",
    "# Date range\n",
    "start = '2016-01-01'\n",
    "end = '2019-12-30'\n",
    "\n",
    "# Tickers of assets\n",
    "assets = ['JCI', 'TGT', 'CMCSA', 'CPB', 'MO', 'APA', 'MMC', 'JPM',\n",
    "          'ZION', 'PSA', 'BAX', 'BMY', 'LUV', 'PCAR', 'TXT', 'TMO',\n",
    "          'DE', 'MSFT', 'HPQ', 'SEE', 'VZ', 'CNP', 'NI', 'T', 'BA']\n",
    "assets.sort()\n",
    "\n",
    "# Downloading data\n",
    "data = yf.download(assets, start = start, end = end)\n",
    "data = data.loc[:,('Adj Close', slice(None))]\n",
    "data.columns = assets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>APA</th>\n",
       "      <th>BA</th>\n",
       "      <th>BAX</th>\n",
       "      <th>BMY</th>\n",
       "      <th>CMCSA</th>\n",
       "      <th>CNP</th>\n",
       "      <th>CPB</th>\n",
       "      <th>DE</th>\n",
       "      <th>HPQ</th>\n",
       "      <th>JCI</th>\n",
       "      <th>...</th>\n",
       "      <th>NI</th>\n",
       "      <th>PCAR</th>\n",
       "      <th>PSA</th>\n",
       "      <th>SEE</th>\n",
       "      <th>T</th>\n",
       "      <th>TGT</th>\n",
       "      <th>TMO</th>\n",
       "      <th>TXT</th>\n",
       "      <th>VZ</th>\n",
       "      <th>ZION</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-10-19</th>\n",
       "      <td>0.0475%</td>\n",
       "      <td>-0.8599%</td>\n",
       "      <td>-1.4332%</td>\n",
       "      <td>-3.0011%</td>\n",
       "      <td>0.1113%</td>\n",
       "      <td>1.2968%</td>\n",
       "      <td>3.4361%</td>\n",
       "      <td>-0.8764%</td>\n",
       "      <td>0.2944%</td>\n",
       "      <td>-0.7834%</td>\n",
       "      <td>...</td>\n",
       "      <td>0.6339%</td>\n",
       "      <td>-0.1823%</td>\n",
       "      <td>0.9186%</td>\n",
       "      <td>-0.7728%</td>\n",
       "      <td>1.1385%</td>\n",
       "      <td>-1.6075%</td>\n",
       "      <td>-1.1144%</td>\n",
       "      <td>-1.2872%</td>\n",
       "      <td>0.4575%</td>\n",
       "      <td>-0.8025%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-10-22</th>\n",
       "      <td>-1.9240%</td>\n",
       "      <td>-0.0786%</td>\n",
       "      <td>-0.6335%</td>\n",
       "      <td>-6.2983%</td>\n",
       "      <td>-0.6393%</td>\n",
       "      <td>-1.1024%</td>\n",
       "      <td>0.0527%</td>\n",
       "      <td>-0.3221%</td>\n",
       "      <td>1.1326%</td>\n",
       "      <td>-0.8199%</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.8662%</td>\n",
       "      <td>0.4483%</td>\n",
       "      <td>-1.6953%</td>\n",
       "      <td>-2.8972%</td>\n",
       "      <td>-0.6085%</td>\n",
       "      <td>1.4752%</td>\n",
       "      <td>-0.6075%</td>\n",
       "      <td>-0.8635%</td>\n",
       "      <td>0.1457%</td>\n",
       "      <td>-3.4490%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-10-23</th>\n",
       "      <td>-3.6571%</td>\n",
       "      <td>-1.6658%</td>\n",
       "      <td>-0.4202%</td>\n",
       "      <td>-0.4520%</td>\n",
       "      <td>-0.2797%</td>\n",
       "      <td>-0.5034%</td>\n",
       "      <td>0.1844%</td>\n",
       "      <td>-3.9948%</td>\n",
       "      <td>-0.7051%</td>\n",
       "      <td>-0.2449%</td>\n",
       "      <td>...</td>\n",
       "      <td>0.4766%</td>\n",
       "      <td>-5.1240%</td>\n",
       "      <td>0.5342%</td>\n",
       "      <td>-0.0321%</td>\n",
       "      <td>1.0713%</td>\n",
       "      <td>-0.6728%</td>\n",
       "      <td>-1.0808%</td>\n",
       "      <td>-1.8308%</td>\n",
       "      <td>4.0560%</td>\n",
       "      <td>4.0353%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-10-24</th>\n",
       "      <td>-4.5500%</td>\n",
       "      <td>1.3141%</td>\n",
       "      <td>-1.8042%</td>\n",
       "      <td>-3.5933%</td>\n",
       "      <td>-4.2917%</td>\n",
       "      <td>0.8674%</td>\n",
       "      <td>0.9995%</td>\n",
       "      <td>-4.1108%</td>\n",
       "      <td>-3.6758%</td>\n",
       "      <td>-3.7139%</td>\n",
       "      <td>...</td>\n",
       "      <td>3.5178%</td>\n",
       "      <td>-4.2683%</td>\n",
       "      <td>1.5636%</td>\n",
       "      <td>-1.3479%</td>\n",
       "      <td>-8.0557%</td>\n",
       "      <td>-0.4838%</td>\n",
       "      <td>-1.2403%</td>\n",
       "      <td>-4.2187%</td>\n",
       "      <td>0.3671%</td>\n",
       "      <td>-3.3065%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-10-25</th>\n",
       "      <td>0.4741%</td>\n",
       "      <td>2.5715%</td>\n",
       "      <td>0.5186%</td>\n",
       "      <td>0.7782%</td>\n",
       "      <td>5.0410%</td>\n",
       "      <td>-0.5733%</td>\n",
       "      <td>-1.1719%</td>\n",
       "      <td>2.1585%</td>\n",
       "      <td>3.1657%</td>\n",
       "      <td>2.3270%</td>\n",
       "      <td>...</td>\n",
       "      <td>-1.0309%</td>\n",
       "      <td>0.4914%</td>\n",
       "      <td>0.5082%</td>\n",
       "      <td>0.9109%</td>\n",
       "      <td>-1.2516%</td>\n",
       "      <td>1.8962%</td>\n",
       "      <td>4.3662%</td>\n",
       "      <td>1.3800%</td>\n",
       "      <td>-1.7241%</td>\n",
       "      <td>3.3538%</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 25 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                APA       BA      BAX      BMY    CMCSA      CNP      CPB  \\\n",
       "Date                                                                        \n",
       "2018-10-19  0.0475% -0.8599% -1.4332% -3.0011%  0.1113%  1.2968%  3.4361%   \n",
       "2018-10-22 -1.9240% -0.0786% -0.6335% -6.2983% -0.6393% -1.1024%  0.0527%   \n",
       "2018-10-23 -3.6571% -1.6658% -0.4202% -0.4520% -0.2797% -0.5034%  0.1844%   \n",
       "2018-10-24 -4.5500%  1.3141% -1.8042% -3.5933% -4.2917%  0.8674%  0.9995%   \n",
       "2018-10-25  0.4741%  2.5715%  0.5186%  0.7782%  5.0410% -0.5733% -1.1719%   \n",
       "\n",
       "                 DE      HPQ      JCI  ...       NI     PCAR      PSA  \\\n",
       "Date                                   ...                              \n",
       "2018-10-19 -0.8764%  0.2944% -0.7834%  ...  0.6339% -0.1823%  0.9186%   \n",
       "2018-10-22 -0.3221%  1.1326% -0.8199%  ... -0.8662%  0.4483% -1.6953%   \n",
       "2018-10-23 -3.9948% -0.7051% -0.2449%  ...  0.4766% -5.1240%  0.5342%   \n",
       "2018-10-24 -4.1108% -3.6758% -3.7139%  ...  3.5178% -4.2683%  1.5636%   \n",
       "2018-10-25  2.1585%  3.1657%  2.3270%  ... -1.0309%  0.4914%  0.5082%   \n",
       "\n",
       "                SEE        T      TGT      TMO      TXT       VZ     ZION  \n",
       "Date                                                                       \n",
       "2018-10-19 -0.7728%  1.1385% -1.6075% -1.1144% -1.2872%  0.4575% -0.8025%  \n",
       "2018-10-22 -2.8972% -0.6085%  1.4752% -0.6075% -0.8635%  0.1457% -3.4490%  \n",
       "2018-10-23 -0.0321%  1.0713% -0.6728% -1.0808% -1.8308%  4.0560%  4.0353%  \n",
       "2018-10-24 -1.3479% -8.0557% -0.4838% -1.2403% -4.2187%  0.3671% -3.3065%  \n",
       "2018-10-25  0.9109% -1.2516%  1.8962%  4.3662%  1.3800% -1.7241%  3.3538%  \n",
       "\n",
       "[5 rows x 25 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Calculating returns\n",
    "\n",
    "Y = data[assets].iloc[-300:,:].pct_change().dropna()\n",
    "\n",
    "display(Y.head())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Estimating OWA Portfolios\n",
    "\n",
    "The OWA portfolio model proposed by __[Cajas (2021)](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3988927)__ . This model gives an alternative formulation to risk measures that can be expressed using the OWA operator.\n",
    "\n",
    "It is recommended to use MOSEK to optimize OWA portfolios, due to it requires more computing power for the number of constraints and variables the model use.\n",
    "\n",
    "Instructions to install MOSEK are in this __[link](https://docs.mosek.com/9.2/install/installation.html)__, is better to install using Anaconda. Also you will need a license, I recommend you that ask for an academic license __[here](https://www.mosek.com/products/academic-licenses/)__.\n",
    "\n",
    "### 2.1 Comparing Classical formulations vs OWA formulations.\n",
    "\n",
    "In this case we are going to compare the optimal weights using classical formulations and owa formulation of two risk measures: Conditional Value at Risk (CVaR) and Worst Realization (WR or Minimax model)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_aaa35_row0_col0, #T_aaa35_row0_col1, #T_aaa35_row0_col2, #T_aaa35_row0_col3, #T_aaa35_row0_col4, #T_aaa35_row0_col5, #T_aaa35_row0_col6, #T_aaa35_row0_col7, #T_aaa35_row0_col8, #T_aaa35_row0_col9, #T_aaa35_row0_col10, #T_aaa35_row0_col11, #T_aaa35_row1_col2, #T_aaa35_row1_col3, #T_aaa35_row1_col4, #T_aaa35_row1_col5, #T_aaa35_row1_col6, #T_aaa35_row1_col7, #T_aaa35_row1_col8, #T_aaa35_row1_col9, #T_aaa35_row1_col10, #T_aaa35_row1_col11, #T_aaa35_row2_col0, #T_aaa35_row2_col1, #T_aaa35_row2_col2, #T_aaa35_row2_col3, #T_aaa35_row2_col4, #T_aaa35_row2_col5, #T_aaa35_row2_col6, #T_aaa35_row2_col7, #T_aaa35_row2_col8, #T_aaa35_row2_col9, #T_aaa35_row2_col10, #T_aaa35_row2_col11, #T_aaa35_row3_col2, #T_aaa35_row3_col5, #T_aaa35_row3_col8, #T_aaa35_row3_col9, #T_aaa35_row3_col10, #T_aaa35_row3_col11, #T_aaa35_row4_col2, #T_aaa35_row4_col3, #T_aaa35_row4_col4, #T_aaa35_row4_col5, #T_aaa35_row4_col6, #T_aaa35_row4_col7, #T_aaa35_row4_col8, #T_aaa35_row4_col9, #T_aaa35_row4_col10, #T_aaa35_row4_col11, #T_aaa35_row5_col2, #T_aaa35_row5_col3, #T_aaa35_row5_col4, #T_aaa35_row5_col5, #T_aaa35_row5_col6, #T_aaa35_row5_col7, #T_aaa35_row5_col8, #T_aaa35_row5_col9, #T_aaa35_row5_col10, #T_aaa35_row5_col11, #T_aaa35_row6_col2, #T_aaa35_row6_col5, #T_aaa35_row6_col6, #T_aaa35_row6_col7, #T_aaa35_row6_col8, #T_aaa35_row6_col11, #T_aaa35_row7_col0, #T_aaa35_row7_col1, #T_aaa35_row7_col2, #T_aaa35_row7_col3, #T_aaa35_row7_col4, #T_aaa35_row7_col5, #T_aaa35_row7_col6, #T_aaa35_row7_col7, #T_aaa35_row7_col8, #T_aaa35_row7_col9, #T_aaa35_row7_col10, #T_aaa35_row7_col11, #T_aaa35_row8_col0, #T_aaa35_row8_col1, #T_aaa35_row8_col2, #T_aaa35_row8_col3, #T_aaa35_row8_col4, #T_aaa35_row8_col5, #T_aaa35_row8_col6, #T_aaa35_row8_col7, #T_aaa35_row8_col8, #T_aaa35_row8_col9, #T_aaa35_row8_col10, #T_aaa35_row8_col11, #T_aaa35_row9_col0, #T_aaa35_row9_col1, #T_aaa35_row9_col2, #T_aaa35_row9_col3, #T_aaa35_row9_col4, #T_aaa35_row9_col5, #T_aaa35_row9_col6, #T_aaa35_row9_col7, #T_aaa35_row9_col8, #T_aaa35_row9_col9, #T_aaa35_row9_col10, #T_aaa35_row9_col11, #T_aaa35_row10_col0, #T_aaa35_row10_col1, #T_aaa35_row10_col2, #T_aaa35_row10_col3, #T_aaa35_row10_col4, #T_aaa35_row10_col5, #T_aaa35_row10_col6, #T_aaa35_row10_col7, #T_aaa35_row10_col8, #T_aaa35_row10_col9, #T_aaa35_row10_col10, #T_aaa35_row10_col11, #T_aaa35_row11_col0, #T_aaa35_row11_col1, #T_aaa35_row11_col2, #T_aaa35_row11_col3, #T_aaa35_row11_col4, #T_aaa35_row11_col5, #T_aaa35_row11_col6, #T_aaa35_row11_col7, #T_aaa35_row11_col8, #T_aaa35_row11_col9, #T_aaa35_row11_col10, #T_aaa35_row11_col11, #T_aaa35_row12_col0, #T_aaa35_row12_col1, #T_aaa35_row12_col2, #T_aaa35_row12_col5, #T_aaa35_row12_col6, #T_aaa35_row12_col7, #T_aaa35_row12_col8, #T_aaa35_row12_col9, #T_aaa35_row12_col10, #T_aaa35_row12_col11, #T_aaa35_row13_col0, #T_aaa35_row13_col1, #T_aaa35_row13_col2, #T_aaa35_row13_col3, #T_aaa35_row13_col4, #T_aaa35_row13_col5, #T_aaa35_row13_col8, #T_aaa35_row13_col9, #T_aaa35_row13_col10, #T_aaa35_row13_col11, #T_aaa35_row14_col0, #T_aaa35_row14_col1, #T_aaa35_row14_col2, #T_aaa35_row14_col3, #T_aaa35_row14_col4, #T_aaa35_row14_col5, #T_aaa35_row14_col6, #T_aaa35_row14_col7, #T_aaa35_row14_col8, #T_aaa35_row14_col9, #T_aaa35_row14_col10, #T_aaa35_row14_col11, #T_aaa35_row15_col0, #T_aaa35_row15_col1, #T_aaa35_row15_col2, #T_aaa35_row15_col3, #T_aaa35_row15_col4, #T_aaa35_row15_col5, #T_aaa35_row15_col6, #T_aaa35_row15_col7, #T_aaa35_row15_col8, #T_aaa35_row15_col9, #T_aaa35_row15_col10, #T_aaa35_row15_col11, #T_aaa35_row16_col0, #T_aaa35_row16_col1, #T_aaa35_row16_col2, #T_aaa35_row16_col5, #T_aaa35_row16_col6, #T_aaa35_row16_col7, #T_aaa35_row16_col8, #T_aaa35_row16_col11, #T_aaa35_row17_col2, #T_aaa35_row17_col5, #T_aaa35_row17_col8, #T_aaa35_row17_col9, #T_aaa35_row17_col10, #T_aaa35_row17_col11, #T_aaa35_row18_col2, #T_aaa35_row18_col3, #T_aaa35_row18_col4, #T_aaa35_row18_col5, #T_aaa35_row18_col8, #T_aaa35_row18_col9, #T_aaa35_row18_col10, #T_aaa35_row18_col11, #T_aaa35_row19_col2, #T_aaa35_row19_col3, #T_aaa35_row19_col4, #T_aaa35_row19_col5, #T_aaa35_row19_col6, #T_aaa35_row19_col7, #T_aaa35_row19_col8, #T_aaa35_row19_col9, #T_aaa35_row19_col10, #T_aaa35_row19_col11, #T_aaa35_row20_col2, #T_aaa35_row20_col5, #T_aaa35_row20_col8, #T_aaa35_row20_col11, #T_aaa35_row21_col0, #T_aaa35_row21_col1, #T_aaa35_row21_col2, #T_aaa35_row21_col5, #T_aaa35_row21_col6, #T_aaa35_row21_col7, #T_aaa35_row21_col8, #T_aaa35_row21_col11, #T_aaa35_row22_col0, #T_aaa35_row22_col1, #T_aaa35_row22_col2, #T_aaa35_row22_col3, #T_aaa35_row22_col4, #T_aaa35_row22_col5, #T_aaa35_row22_col6, #T_aaa35_row22_col7, #T_aaa35_row22_col8, #T_aaa35_row22_col9, #T_aaa35_row22_col10, #T_aaa35_row22_col11, #T_aaa35_row23_col2, #T_aaa35_row23_col3, #T_aaa35_row23_col4, #T_aaa35_row23_col5, #T_aaa35_row23_col6, #T_aaa35_row23_col7, #T_aaa35_row23_col8, #T_aaa35_row23_col9, #T_aaa35_row23_col10, #T_aaa35_row23_col11, #T_aaa35_row24_col0, #T_aaa35_row24_col1, #T_aaa35_row24_col2, #T_aaa35_row24_col3, #T_aaa35_row24_col4, #T_aaa35_row24_col5, #T_aaa35_row24_col6, #T_aaa35_row24_col7, #T_aaa35_row24_col8, #T_aaa35_row24_col9, #T_aaa35_row24_col10, #T_aaa35_row24_col11 {\n",
       "  background-color: #ffffe5;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row1_col0, #T_aaa35_row1_col1 {\n",
       "  background-color: #fdfed9;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row3_col0, #T_aaa35_row3_col1, #T_aaa35_row5_col0, #T_aaa35_row5_col1 {\n",
       "  background-color: #f9fdc4;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row3_col3, #T_aaa35_row3_col4 {\n",
       "  background-color: #feffdf;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row3_col6, #T_aaa35_row3_col7 {\n",
       "  background-color: #f7fcb9;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row4_col0, #T_aaa35_row4_col1 {\n",
       "  background-color: #feffe2;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row6_col0, #T_aaa35_row6_col1 {\n",
       "  background-color: #fbfdce;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row6_col3, #T_aaa35_row6_col4 {\n",
       "  background-color: #ccea9d;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row6_col9, #T_aaa35_row6_col10 {\n",
       "  background-color: #bae394;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row12_col3, #T_aaa35_row12_col4 {\n",
       "  background-color: #dbf1a4;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row13_col6, #T_aaa35_row13_col7 {\n",
       "  background-color: #e1f3a9;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row16_col3, #T_aaa35_row16_col4, #T_aaa35_row21_col9, #T_aaa35_row21_col10 {\n",
       "  background-color: #f7fcbc;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row16_col9, #T_aaa35_row16_col10 {\n",
       "  background-color: #f4fbb7;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row17_col0, #T_aaa35_row17_col1 {\n",
       "  background-color: #d7efa2;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row17_col3, #T_aaa35_row17_col4 {\n",
       "  background-color: #f8fdc1;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row17_col6, #T_aaa35_row17_col7, #T_aaa35_row20_col9, #T_aaa35_row20_col10 {\n",
       "  background-color: #a1d889;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row18_col0, #T_aaa35_row18_col1 {\n",
       "  background-color: #feffde;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row18_col6, #T_aaa35_row18_col7 {\n",
       "  background-color: #f9fdc7;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row19_col0, #T_aaa35_row19_col1 {\n",
       "  background-color: #fcfed6;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row20_col0, #T_aaa35_row20_col1 {\n",
       "  background-color: #fcfed4;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row20_col3, #T_aaa35_row20_col4 {\n",
       "  background-color: #dff3a8;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row20_col6, #T_aaa35_row20_col7 {\n",
       "  background-color: #edf8b2;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row21_col3, #T_aaa35_row21_col4 {\n",
       "  background-color: #ffffe4;\n",
       "  color: #000000;\n",
       "}\n",
       "#T_aaa35_row23_col0, #T_aaa35_row23_col1 {\n",
       "  background-color: #bee596;\n",
       "  color: #000000;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_aaa35\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th class=\"blank level0\" >&nbsp;</th>\n",
       "      <th id=\"T_aaa35_level0_col0\" class=\"col_heading level0 col0\" >Classic MinRisk CVaR</th>\n",
       "      <th id=\"T_aaa35_level0_col1\" class=\"col_heading level0 col1\" >OWA MinRisk CVaR</th>\n",
       "      <th id=\"T_aaa35_level0_col2\" class=\"col_heading level0 col2\" >diff MinRisk CVaR</th>\n",
       "      <th id=\"T_aaa35_level0_col3\" class=\"col_heading level0 col3\" >Classic Sharpe CVaR</th>\n",
       "      <th id=\"T_aaa35_level0_col4\" class=\"col_heading level0 col4\" >OWA Sharpe CVaR</th>\n",
       "      <th id=\"T_aaa35_level0_col5\" class=\"col_heading level0 col5\" >diff Sharpe CVaR</th>\n",
       "      <th id=\"T_aaa35_level0_col6\" class=\"col_heading level0 col6\" >Classic MinRisk WR</th>\n",
       "      <th id=\"T_aaa35_level0_col7\" class=\"col_heading level0 col7\" >OWA MinRisk WR</th>\n",
       "      <th id=\"T_aaa35_level0_col8\" class=\"col_heading level0 col8\" >diff MinRisk WR</th>\n",
       "      <th id=\"T_aaa35_level0_col9\" class=\"col_heading level0 col9\" >Classic Sharpe WR</th>\n",
       "      <th id=\"T_aaa35_level0_col10\" class=\"col_heading level0 col10\" >OWA Sharpe WR</th>\n",
       "      <th id=\"T_aaa35_level0_col11\" class=\"col_heading level0 col11\" >diff Sharpe WR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row0\" class=\"row_heading level0 row0\" >APA</th>\n",
       "      <td id=\"T_aaa35_row0_col0\" class=\"data row0 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row0_col1\" class=\"data row0 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row0_col2\" class=\"data row0 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row0_col3\" class=\"data row0 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row0_col4\" class=\"data row0 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row0_col5\" class=\"data row0 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row0_col6\" class=\"data row0 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row0_col7\" class=\"data row0 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row0_col8\" class=\"data row0 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row0_col9\" class=\"data row0 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row0_col10\" class=\"data row0 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row0_col11\" class=\"data row0 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row1\" class=\"row_heading level0 row1\" >BA</th>\n",
       "      <td id=\"T_aaa35_row1_col0\" class=\"data row1 col0\" >3.79%</td>\n",
       "      <td id=\"T_aaa35_row1_col1\" class=\"data row1 col1\" >3.79%</td>\n",
       "      <td id=\"T_aaa35_row1_col2\" class=\"data row1 col2\" >-0.00%</td>\n",
       "      <td id=\"T_aaa35_row1_col3\" class=\"data row1 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row1_col4\" class=\"data row1 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row1_col5\" class=\"data row1 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row1_col6\" class=\"data row1 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row1_col7\" class=\"data row1 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row1_col8\" class=\"data row1 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row1_col9\" class=\"data row1 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row1_col10\" class=\"data row1 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row1_col11\" class=\"data row1 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row2\" class=\"row_heading level0 row2\" >BAX</th>\n",
       "      <td id=\"T_aaa35_row2_col0\" class=\"data row2 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row2_col1\" class=\"data row2 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row2_col2\" class=\"data row2 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row2_col3\" class=\"data row2 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row2_col4\" class=\"data row2 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row2_col5\" class=\"data row2 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row2_col6\" class=\"data row2 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row2_col7\" class=\"data row2 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row2_col8\" class=\"data row2 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row2_col9\" class=\"data row2 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row2_col10\" class=\"data row2 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row2_col11\" class=\"data row2 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row3\" class=\"row_heading level0 row3\" >BMY</th>\n",
       "      <td id=\"T_aaa35_row3_col0\" class=\"data row3 col0\" >9.47%</td>\n",
       "      <td id=\"T_aaa35_row3_col1\" class=\"data row3 col1\" >9.47%</td>\n",
       "      <td id=\"T_aaa35_row3_col2\" class=\"data row3 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row3_col3\" class=\"data row3 col3\" >1.84%</td>\n",
       "      <td id=\"T_aaa35_row3_col4\" class=\"data row3 col4\" >1.79%</td>\n",
       "      <td id=\"T_aaa35_row3_col5\" class=\"data row3 col5\" >0.05%</td>\n",
       "      <td id=\"T_aaa35_row3_col6\" class=\"data row3 col6\" >12.88%</td>\n",
       "      <td id=\"T_aaa35_row3_col7\" class=\"data row3 col7\" >12.88%</td>\n",
       "      <td id=\"T_aaa35_row3_col8\" class=\"data row3 col8\" >-0.00%</td>\n",
       "      <td id=\"T_aaa35_row3_col9\" class=\"data row3 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row3_col10\" class=\"data row3 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row3_col11\" class=\"data row3 col11\" >0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row4\" class=\"row_heading level0 row4\" >CMCSA</th>\n",
       "      <td id=\"T_aaa35_row4_col0\" class=\"data row4 col0\" >0.87%</td>\n",
       "      <td id=\"T_aaa35_row4_col1\" class=\"data row4 col1\" >0.87%</td>\n",
       "      <td id=\"T_aaa35_row4_col2\" class=\"data row4 col2\" >-0.00%</td>\n",
       "      <td id=\"T_aaa35_row4_col3\" class=\"data row4 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row4_col4\" class=\"data row4 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row4_col5\" class=\"data row4 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row4_col6\" class=\"data row4 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row4_col7\" class=\"data row4 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row4_col8\" class=\"data row4 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row4_col9\" class=\"data row4 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row4_col10\" class=\"data row4 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row4_col11\" class=\"data row4 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row5\" class=\"row_heading level0 row5\" >CNP</th>\n",
       "      <td id=\"T_aaa35_row5_col0\" class=\"data row5 col0\" >9.42%</td>\n",
       "      <td id=\"T_aaa35_row5_col1\" class=\"data row5 col1\" >9.42%</td>\n",
       "      <td id=\"T_aaa35_row5_col2\" class=\"data row5 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row5_col3\" class=\"data row5 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row5_col4\" class=\"data row5 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row5_col5\" class=\"data row5 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row5_col6\" class=\"data row5 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row5_col7\" class=\"data row5 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row5_col8\" class=\"data row5 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row5_col9\" class=\"data row5 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row5_col10\" class=\"data row5 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row5_col11\" class=\"data row5 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row6\" class=\"row_heading level0 row6\" >CPB</th>\n",
       "      <td id=\"T_aaa35_row6_col0\" class=\"data row6 col0\" >6.94%</td>\n",
       "      <td id=\"T_aaa35_row6_col1\" class=\"data row6 col1\" >6.94%</td>\n",
       "      <td id=\"T_aaa35_row6_col2\" class=\"data row6 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row6_col3\" class=\"data row6 col3\" >28.53%</td>\n",
       "      <td id=\"T_aaa35_row6_col4\" class=\"data row6 col4\" >28.52%</td>\n",
       "      <td id=\"T_aaa35_row6_col5\" class=\"data row6 col5\" >0.01%</td>\n",
       "      <td id=\"T_aaa35_row6_col6\" class=\"data row6 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row6_col7\" class=\"data row6 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row6_col8\" class=\"data row6 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row6_col9\" class=\"data row6 col9\" >33.71%</td>\n",
       "      <td id=\"T_aaa35_row6_col10\" class=\"data row6 col10\" >33.71%</td>\n",
       "      <td id=\"T_aaa35_row6_col11\" class=\"data row6 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row7\" class=\"row_heading level0 row7\" >DE</th>\n",
       "      <td id=\"T_aaa35_row7_col0\" class=\"data row7 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row7_col1\" class=\"data row7 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row7_col2\" class=\"data row7 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row7_col3\" class=\"data row7 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row7_col4\" class=\"data row7 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row7_col5\" class=\"data row7 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row7_col6\" class=\"data row7 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row7_col7\" class=\"data row7 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row7_col8\" class=\"data row7 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row7_col9\" class=\"data row7 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row7_col10\" class=\"data row7 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row7_col11\" class=\"data row7 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row8\" class=\"row_heading level0 row8\" >HPQ</th>\n",
       "      <td id=\"T_aaa35_row8_col0\" class=\"data row8 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row8_col1\" class=\"data row8 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row8_col2\" class=\"data row8 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row8_col3\" class=\"data row8 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row8_col4\" class=\"data row8 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row8_col5\" class=\"data row8 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row8_col6\" class=\"data row8 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row8_col7\" class=\"data row8 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row8_col8\" class=\"data row8 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row8_col9\" class=\"data row8 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row8_col10\" class=\"data row8 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row8_col11\" class=\"data row8 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row9\" class=\"row_heading level0 row9\" >JCI</th>\n",
       "      <td id=\"T_aaa35_row9_col0\" class=\"data row9 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row9_col1\" class=\"data row9 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row9_col2\" class=\"data row9 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row9_col3\" class=\"data row9 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row9_col4\" class=\"data row9 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row9_col5\" class=\"data row9 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row9_col6\" class=\"data row9 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row9_col7\" class=\"data row9 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row9_col8\" class=\"data row9 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row9_col9\" class=\"data row9 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row9_col10\" class=\"data row9 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row9_col11\" class=\"data row9 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row10\" class=\"row_heading level0 row10\" >JPM</th>\n",
       "      <td id=\"T_aaa35_row10_col0\" class=\"data row10 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row10_col1\" class=\"data row10 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row10_col2\" class=\"data row10 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row10_col3\" class=\"data row10 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row10_col4\" class=\"data row10 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row10_col5\" class=\"data row10 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row10_col6\" class=\"data row10 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row10_col7\" class=\"data row10 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row10_col8\" class=\"data row10 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row10_col9\" class=\"data row10 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row10_col10\" class=\"data row10 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row10_col11\" class=\"data row10 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row11\" class=\"row_heading level0 row11\" >LUV</th>\n",
       "      <td id=\"T_aaa35_row11_col0\" class=\"data row11 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row11_col1\" class=\"data row11 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row11_col2\" class=\"data row11 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row11_col3\" class=\"data row11 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row11_col4\" class=\"data row11 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row11_col5\" class=\"data row11 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row11_col6\" class=\"data row11 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row11_col7\" class=\"data row11 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row11_col8\" class=\"data row11 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row11_col9\" class=\"data row11 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row11_col10\" class=\"data row11 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row11_col11\" class=\"data row11 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row12\" class=\"row_heading level0 row12\" >MMC</th>\n",
       "      <td id=\"T_aaa35_row12_col0\" class=\"data row12 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row12_col1\" class=\"data row12 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row12_col2\" class=\"data row12 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row12_col3\" class=\"data row12 col3\" >24.42%</td>\n",
       "      <td id=\"T_aaa35_row12_col4\" class=\"data row12 col4\" >24.40%</td>\n",
       "      <td id=\"T_aaa35_row12_col5\" class=\"data row12 col5\" >0.02%</td>\n",
       "      <td id=\"T_aaa35_row12_col6\" class=\"data row12 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row12_col7\" class=\"data row12 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row12_col8\" class=\"data row12 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row12_col9\" class=\"data row12 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row12_col10\" class=\"data row12 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row12_col11\" class=\"data row12 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row13\" class=\"row_heading level0 row13\" >MO</th>\n",
       "      <td id=\"T_aaa35_row13_col0\" class=\"data row13 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row13_col1\" class=\"data row13 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row13_col2\" class=\"data row13 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row13_col3\" class=\"data row13 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row13_col4\" class=\"data row13 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row13_col5\" class=\"data row13 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row13_col6\" class=\"data row13 col6\" >21.61%</td>\n",
       "      <td id=\"T_aaa35_row13_col7\" class=\"data row13 col7\" >21.61%</td>\n",
       "      <td id=\"T_aaa35_row13_col8\" class=\"data row13 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row13_col9\" class=\"data row13 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row13_col10\" class=\"data row13 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row13_col11\" class=\"data row13 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row14\" class=\"row_heading level0 row14\" >MSFT</th>\n",
       "      <td id=\"T_aaa35_row14_col0\" class=\"data row14 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row14_col1\" class=\"data row14 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row14_col2\" class=\"data row14 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row14_col3\" class=\"data row14 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row14_col4\" class=\"data row14 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row14_col5\" class=\"data row14 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row14_col6\" class=\"data row14 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row14_col7\" class=\"data row14 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row14_col8\" class=\"data row14 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row14_col9\" class=\"data row14 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row14_col10\" class=\"data row14 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row14_col11\" class=\"data row14 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row15\" class=\"row_heading level0 row15\" >NI</th>\n",
       "      <td id=\"T_aaa35_row15_col0\" class=\"data row15 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row15_col1\" class=\"data row15 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row15_col2\" class=\"data row15 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row15_col3\" class=\"data row15 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row15_col4\" class=\"data row15 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row15_col5\" class=\"data row15 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row15_col6\" class=\"data row15 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row15_col7\" class=\"data row15 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row15_col8\" class=\"data row15 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row15_col9\" class=\"data row15 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row15_col10\" class=\"data row15 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row15_col11\" class=\"data row15 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row16\" class=\"row_heading level0 row16\" >PCAR</th>\n",
       "      <td id=\"T_aaa35_row16_col0\" class=\"data row16 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row16_col1\" class=\"data row16 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row16_col2\" class=\"data row16 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row16_col3\" class=\"data row16 col3\" >11.95%</td>\n",
       "      <td id=\"T_aaa35_row16_col4\" class=\"data row16 col4\" >12.00%</td>\n",
       "      <td id=\"T_aaa35_row16_col5\" class=\"data row16 col5\" >-0.05%</td>\n",
       "      <td id=\"T_aaa35_row16_col6\" class=\"data row16 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row16_col7\" class=\"data row16 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row16_col8\" class=\"data row16 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row16_col9\" class=\"data row16 col9\" >13.79%</td>\n",
       "      <td id=\"T_aaa35_row16_col10\" class=\"data row16 col10\" >13.79%</td>\n",
       "      <td id=\"T_aaa35_row16_col11\" class=\"data row16 col11\" >0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row17\" class=\"row_heading level0 row17\" >PSA</th>\n",
       "      <td id=\"T_aaa35_row17_col0\" class=\"data row17 col0\" >25.41%</td>\n",
       "      <td id=\"T_aaa35_row17_col1\" class=\"data row17 col1\" >25.41%</td>\n",
       "      <td id=\"T_aaa35_row17_col2\" class=\"data row17 col2\" >-0.00%</td>\n",
       "      <td id=\"T_aaa35_row17_col3\" class=\"data row17 col3\" >10.27%</td>\n",
       "      <td id=\"T_aaa35_row17_col4\" class=\"data row17 col4\" >10.22%</td>\n",
       "      <td id=\"T_aaa35_row17_col5\" class=\"data row17 col5\" >0.06%</td>\n",
       "      <td id=\"T_aaa35_row17_col6\" class=\"data row17 col6\" >40.27%</td>\n",
       "      <td id=\"T_aaa35_row17_col7\" class=\"data row17 col7\" >40.27%</td>\n",
       "      <td id=\"T_aaa35_row17_col8\" class=\"data row17 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row17_col9\" class=\"data row17 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row17_col10\" class=\"data row17 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row17_col11\" class=\"data row17 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row18\" class=\"row_heading level0 row18\" >SEE</th>\n",
       "      <td id=\"T_aaa35_row18_col0\" class=\"data row18 col0\" >2.27%</td>\n",
       "      <td id=\"T_aaa35_row18_col1\" class=\"data row18 col1\" >2.27%</td>\n",
       "      <td id=\"T_aaa35_row18_col2\" class=\"data row18 col2\" >-0.00%</td>\n",
       "      <td id=\"T_aaa35_row18_col3\" class=\"data row18 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row18_col4\" class=\"data row18 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row18_col5\" class=\"data row18 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row18_col6\" class=\"data row18 col6\" >8.76%</td>\n",
       "      <td id=\"T_aaa35_row18_col7\" class=\"data row18 col7\" >8.76%</td>\n",
       "      <td id=\"T_aaa35_row18_col8\" class=\"data row18 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row18_col9\" class=\"data row18 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row18_col10\" class=\"data row18 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row18_col11\" class=\"data row18 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row19\" class=\"row_heading level0 row19\" >T</th>\n",
       "      <td id=\"T_aaa35_row19_col0\" class=\"data row19 col0\" >4.52%</td>\n",
       "      <td id=\"T_aaa35_row19_col1\" class=\"data row19 col1\" >4.52%</td>\n",
       "      <td id=\"T_aaa35_row19_col2\" class=\"data row19 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row19_col3\" class=\"data row19 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row19_col4\" class=\"data row19 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row19_col5\" class=\"data row19 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row19_col6\" class=\"data row19 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row19_col7\" class=\"data row19 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row19_col8\" class=\"data row19 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row19_col9\" class=\"data row19 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row19_col10\" class=\"data row19 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row19_col11\" class=\"data row19 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row20\" class=\"row_heading level0 row20\" >TGT</th>\n",
       "      <td id=\"T_aaa35_row20_col0\" class=\"data row20 col0\" >4.85%</td>\n",
       "      <td id=\"T_aaa35_row20_col1\" class=\"data row20 col1\" >4.85%</td>\n",
       "      <td id=\"T_aaa35_row20_col2\" class=\"data row20 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row20_col3\" class=\"data row20 col3\" >22.28%</td>\n",
       "      <td id=\"T_aaa35_row20_col4\" class=\"data row20 col4\" >22.31%</td>\n",
       "      <td id=\"T_aaa35_row20_col5\" class=\"data row20 col5\" >-0.03%</td>\n",
       "      <td id=\"T_aaa35_row20_col6\" class=\"data row20 col6\" >16.48%</td>\n",
       "      <td id=\"T_aaa35_row20_col7\" class=\"data row20 col7\" >16.48%</td>\n",
       "      <td id=\"T_aaa35_row20_col8\" class=\"data row20 col8\" >-0.00%</td>\n",
       "      <td id=\"T_aaa35_row20_col9\" class=\"data row20 col9\" >40.40%</td>\n",
       "      <td id=\"T_aaa35_row20_col10\" class=\"data row20 col10\" >40.40%</td>\n",
       "      <td id=\"T_aaa35_row20_col11\" class=\"data row20 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row21\" class=\"row_heading level0 row21\" >TMO</th>\n",
       "      <td id=\"T_aaa35_row21_col0\" class=\"data row21 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row21_col1\" class=\"data row21 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row21_col2\" class=\"data row21 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row21_col3\" class=\"data row21 col3\" >0.70%</td>\n",
       "      <td id=\"T_aaa35_row21_col4\" class=\"data row21 col4\" >0.76%</td>\n",
       "      <td id=\"T_aaa35_row21_col5\" class=\"data row21 col5\" >-0.06%</td>\n",
       "      <td id=\"T_aaa35_row21_col6\" class=\"data row21 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row21_col7\" class=\"data row21 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row21_col8\" class=\"data row21 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row21_col9\" class=\"data row21 col9\" >12.09%</td>\n",
       "      <td id=\"T_aaa35_row21_col10\" class=\"data row21 col10\" >12.09%</td>\n",
       "      <td id=\"T_aaa35_row21_col11\" class=\"data row21 col11\" >0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row22\" class=\"row_heading level0 row22\" >TXT</th>\n",
       "      <td id=\"T_aaa35_row22_col0\" class=\"data row22 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row22_col1\" class=\"data row22 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row22_col2\" class=\"data row22 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row22_col3\" class=\"data row22 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row22_col4\" class=\"data row22 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row22_col5\" class=\"data row22 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row22_col6\" class=\"data row22 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row22_col7\" class=\"data row22 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row22_col8\" class=\"data row22 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row22_col9\" class=\"data row22 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row22_col10\" class=\"data row22 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row22_col11\" class=\"data row22 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row23\" class=\"row_heading level0 row23\" >VZ</th>\n",
       "      <td id=\"T_aaa35_row23_col0\" class=\"data row23 col0\" >32.46%</td>\n",
       "      <td id=\"T_aaa35_row23_col1\" class=\"data row23 col1\" >32.46%</td>\n",
       "      <td id=\"T_aaa35_row23_col2\" class=\"data row23 col2\" >-0.00%</td>\n",
       "      <td id=\"T_aaa35_row23_col3\" class=\"data row23 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row23_col4\" class=\"data row23 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row23_col5\" class=\"data row23 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row23_col6\" class=\"data row23 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row23_col7\" class=\"data row23 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row23_col8\" class=\"data row23 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row23_col9\" class=\"data row23 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row23_col10\" class=\"data row23 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row23_col11\" class=\"data row23 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_aaa35_level0_row24\" class=\"row_heading level0 row24\" >ZION</th>\n",
       "      <td id=\"T_aaa35_row24_col0\" class=\"data row24 col0\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row24_col1\" class=\"data row24 col1\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row24_col2\" class=\"data row24 col2\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row24_col3\" class=\"data row24 col3\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row24_col4\" class=\"data row24 col4\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row24_col5\" class=\"data row24 col5\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row24_col6\" class=\"data row24 col6\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row24_col7\" class=\"data row24 col7\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row24_col8\" class=\"data row24 col8\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row24_col9\" class=\"data row24 col9\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row24_col10\" class=\"data row24 col10\" >0.00%</td>\n",
       "      <td id=\"T_aaa35_row24_col11\" class=\"data row24 col11\" >-0.00%</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x17890f090>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import riskfolio as rp\n",
    "import mosek\n",
    "\n",
    "# Building the portfolio object\n",
    "port = rp.Portfolio(returns=Y)\n",
    "\n",
    "# Calculating optimum portfolio\n",
    "\n",
    "# Select method and estimate input parameters:\n",
    "\n",
    "method_mu='hist' # Method to estimate expected returns based on historical data.\n",
    "method_cov='hist' # Method to estimate covariance matrix based on historical data.\n",
    "\n",
    "port.assets_stats(method_mu=method_mu, method_cov=method_cov)\n",
    "\n",
    "# Estimate optimal portfolios:\n",
    "\n",
    "port.solvers = ['MOSEK'] # It is recommended to use mosek when optimizing GMD\n",
    "port.sol_params = {'MOSEK': {'mosek_params': {mosek.iparam.num_threads: 2}}}\n",
    "alpha = 0.05\n",
    "\n",
    "port.alpha = alpha\n",
    "model ='Classic' # Could be Classic (historical), BL (Black Litterman) or FM (Factor Model)\n",
    "rms = ['CVaR', 'WR'] # Risk measure used, this time will be CVaR and Worst Realization\n",
    "objs = ['MinRisk', 'Sharpe'] # Objective function, could be MinRisk, MaxRet, Utility or Sharpe\n",
    "hist = True # Use historical scenarios for risk measures that depend on scenarios\n",
    "rf = 0 # Risk free rate\n",
    "l = 0 # Risk aversion factor, only useful when obj is 'Utility'\n",
    "\n",
    "ws = pd.DataFrame([])\n",
    "for rm in rms:\n",
    "    for obj in objs:\n",
    "        # Using Classical models\n",
    "        w = port.optimization(model=model, rm=rm, obj=obj, rf=rf, l=l, hist=hist)\n",
    "        # Using OWA model\n",
    "        if rm == \"CVaR\":\n",
    "            owa_w = rp.owa_cvar(len(Y), alpha=alpha)\n",
    "        elif rm == 'WR':\n",
    "            owa_w = rp.owa_wr(len(Y))\n",
    "        w1 = port.owa_optimization(obj=obj, owa_w=owa_w, rf=rf, l=l)\n",
    "        ws1 = pd.concat([w, w1], axis=1)\n",
    "        ws1.columns = ['Classic ' + obj + ' ' + rm, 'OWA ' + obj + ' ' + rm]\n",
    "        ws1['diff ' + obj + ' ' + rm] = ws1['Classic ' + obj + ' ' + rm] - ws1['OWA ' + obj + ' ' + rm]\n",
    "        ws = pd.concat([ws, ws1], axis=1)\n",
    "\n",
    "ws.style.format(\"{:.2%}\").background_gradient(cmap='YlGn', vmin=0, vmax=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As we can see, classical and OWA formulations give us the same returns because both problem are equivalent."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
